package cn.com.elite;

import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

public class EliteBean {
	private static final Log log=LogFactory.getLog(EliteBean.class);
	private DataSource dataSource;
    private DataSourceTransactionManager tran;
	public DataSource getDataSource() {
		return dataSource;
	}
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	public DataSourceTransactionManager getTran() {
		return tran;
	}
	public void setTran(DataSourceTransactionManager tran) {
		this.tran = tran;
	}
	public List chaxunList(String sql){
    	try{
    		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            List resultList=jdbcTemplate.queryForList(sql);
            return resultList;
		}catch(Exception e){
			log.error(sql+":"+Util.getERRO(e));
			return null;
		}
    }
	public int chaxunint(String sql){
    	try{
    		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            int resultList=jdbcTemplate.queryForInt(sql);
            return resultList;
		}catch(Exception e){
			log.error(sql+":"+Util.getERRO(e));
			return 0;
		}		
	}
	public String chaxunString(String sql) throws Exception{
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        String resultList="";
        try{
        	resultList=(String)jdbcTemplate.queryForObject(sql,java.lang.String.class);
        }catch(Exception e){
        	log.info(sql+":"+e);
        }
        return resultList;		
	}
	public int update_sql(String sql){
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    	int result=0;
    	try{
    		result=jdbcTemplate.update(sql);
    	}catch(Exception e){
    		log.info(sql+":"+e);
    	}
		return result;
	}
}
